// 用户个人资料-个人认证
var certification = Vue.component('certification', {
    data () {
        return {
            isEdit: false,          // 是否编辑
            dialogImageUrl: '',     // 用户上传的图片
            dialogVisible: false,   // 用户形象
            eduData: [              // 教育的选项
                { value: 1, label: '小学' },
                { value: 2, label: '初中' },
                { value: 3, label: '高中/中专/职高' },
                { value: 4, label: '本科' },
                { value: 5, label: '研究生' },
                { value: 6, label: '博士' },
                { value: 7, label: '其他' }
            ],
            marryData: [            // 婚姻状况的选项
                { value: 1, label: '未婚' },
                { value: 2, label: '已婚' },
                { value: 3, label: '离异' },
                { value: 4, label: '丧偶' }
            ],
            houseData: [            // 住宿需要
                { value: 'xuyao', label: '需要' },
                { value: 'buxuyao', label: '不需要' }
            ],
            userInfo: {}
        }
    },
    created() {
        var self = this;
        $.ajax({
            type:"POST",
            url: _UrlPrefix + "/api/member/staff/show",
            xhrFields: {
              withCredentials: true
            },
            data: {
                app_access: _AppAccess
            },
            success:function(res){
                if(0 == res.code) {
                    console.log("res: ", res)
                    self.userInfo = res.data;
                }
            }
        })
    },
    methods: {
        onEditFun () {
            this.isEdit = !this.isEdit;
        },
        onSaveEdit () {
            // 保存设置
            console.log("保存设置");
            let self = this;
            // this.userInfo.image = this.dialogImageUrl;
            let _data = {
                app_access: _AppAccess,
                token: "不使用",
                "staffInfos[jobType]": this.userInfo.job,
                "staffInfos[job_str]": this.userInfo.job_str,
                "staffInfos[realname]": this.userInfo.realname,
                "staffInfos[sex]": this.userInfo.sex,
                "staffInfos[birth]": this.userInfo.birth,
                "staffInfos[edu]": this.userInfo.edu,
                "staffInfos[weight]": this.userInfo.weight,
                "staffInfos[polity]": this.userInfo.polity,
                "staffInfos[origin]": this.userInfo.origin,
                "staffInfos[nation]": this.userInfo.nation,
                "staffInfos[marry]": this.userInfo.marry,
                "staffInfos[idcard]": this.userInfo.idcard,
                "staffInfos[house]": this.userInfo.house,
                "staffInfos[xxz]": this.userInfo.image,
                "staffInfos[address]": this.userInfo.houseAddress,
                "staffInfos[live]": this.userInfo.liveAddress,
                "staffInfos[person]": this.userInfo.contactPerson,
                "staffInfos[mobile]": this.userInfo.contactMobile,
                "staffInfos[salary]": this.userInfo.salary
            }
            $.ajax({
                type:"POST",
                url: _UrlPrefix + "/api/member/staff/modify",
                xhrFields: {
                  withCredentials: true
                },
                data: _data,
                success:function(res){
                    console.log(res)
                    if(0 == res.code) {
                        console.log("res: ", res)
                        self.isEdit = false;
                    }
                }
            })
            // this.isEdit = false;
        },
        handleChange(response, file, fileList) {
            // 获取上传的资源
            this.dialogImageUrl = file[0].url;
            console.log("response: ", response);
            console.log("file: ", file);
            console.log("fileList: ", fileList);
        },
        handleRemove(file, fileList) {
            // 删除上传的形象照
            console.log(file, fileList);
        },
        handlePictureCardPreview (file) {
            // 形象照的预览
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
        }
    },
    template: ` <div class="data-certification">
                    <div class="content">
                        <div class="contents">
                            <div class="one-row rows">
                                <div class="name">本人照片：</div>
                                <div class="detail">
                                    <div>
                                        <img />
                                    </div>
                                    <div><input type="file" /></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>`
})